2 using System.Collections.Generic;
5 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Graphics;
8 namespace SuperPolarity
12 private Random random;
13 public Vector2 EmitterLocation { get; set; }
15 private List<Particle> particles;
16 private List<Texture2D> textures;
18 public ParticleEngine(List<Texture2D> textures, Vector2 location)
20 EmitterLocation = location;
21 this.textures = textures;
22 this.particles = new List<Particle>();
23 random = new Random();
27 private Particle GenerateNewParticle()
29 Texture2D texture = textures[random.Next(textures.Count)];
30 Vector2 position = EmitterLocation;
31 Vector2 velocity = new Vector2(
32 1f * (float)(random.NextDouble() * 2 - 1),
33 1f * (float)(random.NextDouble() * 2 - 1));
35 float angularVelocity = 0.1f * (float)(random.NextDouble() * 2 - 1);
37 float size = (float)random.NextDouble();
39 int ttl = 20 + random.Next(40);
41 return new Particle(texture, position, velocity, angle, angularVelocity, color, size, ttl);
48 for (int i = 0; i < total; i++)
50 particles.Add(GenerateNewParticle());
53 for (int particle = 0; particle < particles.Count; particle++)
55 particles[particle].Update();
56 if (particles[particle].TTL <= 0)
58 particles.RemoveAt(particle);
64 public void Draw(SpriteBatch spriteBatch)
66 //spriteBatch.Begin();
67 for (int index = 0; index < particles.Count; index++)
69 particles[index].Draw(spriteBatch);